package com.hll.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpSession;

/**
 * @author: Mr.Hu
 * @create: 2021-03-13 22:21
 */
@Controller
@RequestMapping("/user")
public class UserController {

  // 跳转到登陆页面
  @RequestMapping("/jumplogin")
  public String jumpLogin() throws Exception {
    return "login";
  }

  // 跳转到成功页面
  @RequestMapping("/jumpSuccess")
  public String jumpSuccess() throws Exception {
    return "success";
  }

  // 登陆提交
  @RequestMapping("/login")
  public String login(HttpSession session, String username, String pwd) throws Exception {
    // 向session记录用户身份信息
    System.out.println("接收前端===" + username);
    session.setAttribute("user", username);
    return "success";
  }

  // 退出登陆
  @RequestMapping("logout")
  public String logout(HttpSession session) throws Exception {
    // session 过期
    session.invalidate();
    return "login";
  }
}
